package com.example.zhangwei.widgts.dialog;

import com.example.zhangwei.R;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

public class androidTVDialog extends AlertDialog
{
    private androidTVDialogView view;

    private Context mContext;
    
    private LinearLayout mConfirmLayout;
    private LinearLayout mBackLayout;
    

    protected androidTVDialog(Context context)
    {
        super(context,R.style.DailogTransparent);//自定义样式
        this.mContext = context;
        LayoutInflater inflater = LayoutInflater.from(this.mContext);
        view = (androidTVDialogView) inflater.inflate(R.layout.dialog_androidtv_new, null);  
    }

    @SuppressWarnings("deprecation")
	@SuppressLint("NewApi")
	@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN,      
//                WindowManager.LayoutParams. FLAG_FULLSCREEN);//去除状态栏   
        if (android.os.Build.VERSION.SDK_INT < 14)
        	getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
        			WindowManager.LayoutParams.FLAG_BLUR_BEHIND);//使用模糊效果   
        setContentView(view);
    }
    

    @Override
    public void setMessage(CharSequence message)
    {
        view.setMessage(message);
    }

    @Override
    public void setTitle(CharSequence title)
    {
        view.setTitle(title);
    }

    @SuppressWarnings("deprecation")
	@Override
    public void setButton(CharSequence text, final OnClickListener listener)
    {
        mConfirmLayout = (LinearLayout) view.findViewById(R.id.dialog_confirm_layout);
        mConfirmLayout.setVisibility(View.VISIBLE);
        
        TextView txtConfirm = (TextView) view.findViewById(R.id.tv_dialog_confirm_txt);
        txtConfirm.setText(text);
        txtConfirm.setVisibility(View.VISIBLE);
        
        mConfirmLayout.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                listener.onClick(androidTVDialog.this, 0);
                dismiss();
            }
        });

        super.setButton(text, listener);
    }

    @SuppressWarnings("deprecation")
	@Override
    public void setButton2(CharSequence text, final OnClickListener listener)
    {
        // Button button = (Button) view.findViewById(R.id.dialog_no);
        // button.setText(text);
        // button.setVisibility(View.VISIBLE);
        // button.setOnClickListener(new View.OnClickListener() {
        //
        // public void onClick(View view) {
        // listener.onClick(androidTVDialog.this, 0);
        // dismiss();
        // }
        // });
        super.setButton2(text, listener);
    }

    @SuppressWarnings("deprecation")
	@Override
    public void setButton3(CharSequence text, final OnClickListener listener)
    {
        mBackLayout = (LinearLayout) view.findViewById(R.id.dialog_back_layout);
        mBackLayout.setVisibility(View.VISIBLE);
        
        TextView txtBack = (TextView) view.findViewById(R.id.tv_dialog_back_txt);
        txtBack.setText(text);
        txtBack.setVisibility(View.VISIBLE);
        
        TextView imgConfirm = (TextView) view.findViewById(R.id.tv_dialog_confirm_img);
        TextView imgBack = (TextView) view.findViewById(R.id.tv_dialog_back_img);
        imgConfirm.setVisibility(View.VISIBLE);
        imgBack.setVisibility(View.VISIBLE);
        
        mBackLayout.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                listener.onClick(androidTVDialog.this, 0);
                dismiss();
            }
        });
        
        super.setButton3(text, listener);
    }
}
